<template>
	<view class="help-container">
		<uni-forms ref="form" :modelValue="formData" label-width="80px">
			<uni-forms-item label="专家类型" name="type">
				<uni-data-select v-model="formData.type" :localdata="range"></uni-data-select>
			</uni-forms-item>
			<uni-forms-item label="专家昵称" name="nick">
				<uni-easyinput type="text" v-model="formData.nick" placeholder="请输入专家昵称" />
			</uni-forms-item>
			<uni-forms-item label="从事经验" name="age">
				<uni-easyinput type="text" v-model="formData.age" placeholder="请输入专家昵称" />
			</uni-forms-item>
			<uni-forms-item label="姓名" name="name">
				<uni-easyinput type="text" v-model="formData.name" placeholder="请输入专家昵称" />
			</uni-forms-item>
			<uni-forms-item label="用户性别" name="sex">
				<uni-data-checkbox v-model="formData.sex" :localdata="sexs" />
			</uni-forms-item>
			<uni-forms-item label="用户邮箱" name="email">
				<uni-easyinput type="text" v-model="formData.email" placeholder="请输入专家昵称" />
			</uni-forms-item>
			<uni-forms-item label="手机号码" name="phonenumber">
				<uni-easyinput type="text" v-model="formData.phonenumber" placeholder="请输入专家昵称" />
			</uni-forms-item>
			<uni-forms-item label="自我介绍" name="intro">
				<uni-easyinput type="textarea" v-model="formData.intro" placeholder="请输入专家昵称" />
			</uni-forms-item>
		</uni-forms>

		<button @click="sumit" class="login-btn cu-btn block bg-blue lg round" v-if="ifSumit">提交</button>
	</view>
</template>

<script>
	import {
		addZj,
		updateZj,
		getZj
	} from '@/api/system/zj.js'
	import {
		updateUserProfile,getUser,
		getUserProfile,updateUser
	} from '@/api/system/user.js'
	export default {
		data() {
			return {
				formData: {},
				ifSumit: true,
				userInfo: {},
				range: [{
						value: 0,
						text: "男"
					},
					{
						value: 1,
						text: "女"
					},
					{
						value: 2,
						text: "其他"
					},
				],
				sexs: [{
					text: '男',
					value: "0"
				}, {
					text: '女',
					value: "1"
				}],
			}
		},
		onLoad() { 
			this.getUser()
		},
		onReady() {},
		methods: {
			getUser() { 
				getUser(this.$store.state.user.userInfo.userId).then(response => {
					this.userInfo = response.data
					console.log(this.userInfo)
					if (this.userInfo.zjId != null) {
						getZj(this.userInfo.zjId).then(res => {
							this.formData = res.data 
							console.log(this.formData)
						})
					} 
				})
			},
			sumit() {
				this.$refs.form.validate().then(res => {
					this.ifSumit = false
					if (this.formData.zhuanjiaId == null) {
						this.formData.userId = this.userInfo.userId
						addZj(this.formData).then(response => {
							console.log(response)
							if (response.code === 200) {
								this.userInfo.zjId = response.data.zhuanjiaId
								console.log(this.userInfo)
								updateUser(this.userInfo).then(res => {
									if (response.code === 200) {
										this.$modal.msgSuccess("新增专家认证成功")
										this.ifSumit = false
									} else {
										this.ifSumit = true
									} 
								})
							} else {
								this.ifSumit = true
							}
						})
					}

				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f8f8f8;
	}

	.help-container {
		margin-bottom: 100rpx;
		padding: 30rpx;
	}

	.list-title {
		margin-bottom: 30rpx;
	}

	.childList {
		background: #ffffff;
		box-shadow: 0px 0px 10rpx rgba(193, 193, 193, 0.2);
		border-radius: 16rpx;
		margin-top: 10rpx;
	}

	.line {
		width: 100%;
		height: 1rpx;
		background-color: #F5F5F5;
	}

	.text-title {
		color: #303133;
		font-size: 32rpx;
		font-weight: bold;
		margin-left: 10rpx;

		.iconfont {
			font-size: 16px;
			margin-right: 10rpx;
		}
	}

	.text-item {
		font-size: 28rpx;
		padding: 24rpx;
	}

	.question {
		color: #606266;
		font-size: 28rpx;
	}
</style>